import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

// 命名规范：use****Store
const useCountStore = defineStore('count', () => {
  // 1.定义数据(状态-state)
  const count = ref(2)
  const price = ref(10)

  // 2.数据的获取器getter，等同于组件的计算属性computed
  const totalPrice = computed(() => {
    return count.value * price.value
  })

  // 3.数据修改器(action)
  const incCount = () => {
    // 发送ajax请求
    count.value++
  }

  // 需要通过一个对象返回出去
  return {
    count,
    price,
    totalPrice,
    incCount,
  }
})

// 将仓库进行导出
export default useCountStore
